﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcPaging;
using System.Web.Mvc;
using Test.Utility.Extensions;

namespace Test.Site.Data.Models
{
    public class PagedListModel<T>
    {
        public PagedListModel()
        {
            Page = 1;
            Size = 10;
            QueryParameter = new ViewDataDictionary();
        }

        public void AddQueryParameter(string key, string value)
        {
            if (key.IsNotNullAndNotWhiteSpace() && value.IsNotNullAndNotWhiteSpace())
            {
                QueryParameter[key] = value;
            }
        }

        /// <summary>
        /// MvcPaging的分页数据
        /// </summary>
        public IPagedList<T> PagedList { get; set; }

        /// <summary>
        /// 查询字符串的参数集
        /// </summary>
        public ViewDataDictionary QueryParameter {get;set;}

        /// <summary>
        /// 查询关键字
        /// </summary>
        public string Keyword { get; set; }

        /// <summary>
        /// 每页大小
        /// </summary>
        public int Size { get; set; }

        /// <summary>
        /// 当前页数
        /// </summary>
        public int Page { get; set; }

        /// <summary>
        /// 当前页数索引，从0开始，MvcPaging需要
        /// </summary>
        public int PageIndex
        {
            get
            {
                return (Page -1 < 0) ? 0 : (Page - 1);
            }
        }
    }
}